package com.flower.baseservice.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.jwt.crypto.sign.RsaVerifier;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @ClassName ResourceConfig
 * @Description 解析jwt
 * @Author 张晓焕
 * @Date 2022/7/13 14:35
 * @Version 1.0
 */
@Configuration
public class ResourceConfig extends ResourceServerConfigurerAdapter {
    @Autowired
    TokenStore tokenStore;

    /**
     * @author 吃麻椒的花酱
     * @date 2022/7/13 16:33
     * @Description token转换器
     * @param
     * @return org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter jwt= new JwtAccessTokenConverter();
        jwt.setSigningKey("flowerhua");
        jwt.setVerifierKey("flowerhua");
        return jwt;
    }

    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
        resources.tokenStore(tokenStore).stateless(true);
    }
}
